<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%--
  Created by IntelliJ IDEA.
  User: zuti666
  Date: 2020/6/23
  Time: 10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>backend</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/bootstarp/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/css/index.css" />
    <script src="${pageContext.request.contextPath}/statics/js/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/bootstarp/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/js/userSetting.js" type="text/javascript" charset="utf-8"></script>
    <!-- 引入bootstrap分页插件 -->
    <script src="${pageContext.request.contextPath }/statics/js/bootstrap-paginator.js" type="text/javascript" charset="utf-8"></script>

    <style>
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
            width: 100%;
            text-align: center;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>

    <script type="text/javascript">
        $(function()
        {

        // 添加商品
        function addProduct()
        {
            $("#addFrmProduct").submit();
        }

        $(function()
        {
            // 修改商品
            $("input[name='toModify']").click(function()
            {
                $.ajax(
                    {
                        type : "post",
                        url  : "${pageContext.request.contextPath}/product/findById",
                        data : {"id" : $(this).attr("data-value")},
                        dataType : "json",
                        success : function(result)
                        {
                            if (result.responseCode == 1)
                            {
                                // alert(result.returnObject.name);
                                $("#modifyId").val(result.returnObject.productId);
                                $("#modifyName").val(result.returnObject.name);
                                $("#modifyPrice").val(result.returnObject.price);
                                $("#modifyTypeId").find("option[value='" + result.returnObject.productType.id + "']").attr("selected", true);
                            }
                        }
                    });
            });


        });

     });


    </script>

</head>

<body>
<div class="panel panel-default" id="userPic">
    <div class="panel-heading">
        <h3 class="panel-title">商品管理</h3>
    </div>
    <div class="panel-body">
        <input type="button" value="添加商品" class="btn btn-primary" id="doAddPro">
        <div class="modal fade" tabindex="-1" id="Product">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">添加商品</h4>
                    </div>
                    <!--
                                                         添加form表单: 文件上传必须要有form表单  提交方式必须是post enctype="multipart/form-data"
                                                         添加 id="addFrmProduct"
                                                         通过js代码让表单提交
-->
                    <form action="${pageContext.request.contextPath }/product/addProduct" method="post" id="addFrmProduct" enctype="multipart/form-data">
                    <div class="modal-body text-center">
                        <!-- 添加  商品编号 div  -->
                        <div class="row text-right">
                            <label for="addProductNo" class="col-sm-4 control-label">商品编号</label>
                            <div class="col-sm-4">
                                <!--  添加 name="productNo"-->
                                <input type="text" class="form-control" id="addProductNo" name="addProductNo">

                            </div>
                        </div>

                        <br/>
                        <div class="row text-right">
                            <label for="addProductName" class="col-sm-4 control-label">商品名称：</label>
                            <div class="col-sm-4">
                                <!--  添加 一个隐藏域 用于传递pageNo(用户点击的是第几页) 到后台ProductController类中的addProduct()方法中去 -->
                                <input type="hidden" name="pageIndex" value="${pageSupport.currentPageNo}" />
                                <input type="text" class="form-control" id="addProductName" name="addProductName">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="addProductPrice" class="col-sm-4 control-label">商品价格：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="addProductPrice" name="addProductPrice">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">商品图片：</label>
                            <div class="col-sm-4">
                                <a href="javascript:;" class="file">选择文件
                                    <input type="file" name="file" >
                                </a>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">商品类型：</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="typeId" id="typeId">
                                    <option value = "">--请选择--</option>
                                    <c:forEach items="${typeList }" var="type">
                                        <option value="${type.id }">${type.name }</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <br>
                    </div>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-primary addProduct" value="添加"  onclick="addProduct();" />
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <br>
        <br>
        <div class="show-list">
            <form method="post" action="">
                <input type="hidden" name="pageIndex" value="1"/>
            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">编号</th>
                    <th class="text-center">商品</th>
                    <th class="text-center">价格</th>
                    <th class="text-center">产品类型</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                <c:forEach items="${ProductList}" var="p" varStatus="i">
                    <tr>
                        <td>${p.productNo }</td>
                        <td>${p.name }</td>
                        <td>${p.price }</td>
                        <td>${p.productType.name }</td>
                        <td>
                            <c:if test="${p.productType.status eq 1 }">有效商品</c:if>
                            <c:if test="${p.productType.status eq 0 }">无效商品</c:if>
                        </td>

                        <td class="text-center">
                            <!-- 添加 name="toModify" 和 data-value="${p.productId }" -->
                            <input type="button" class="btn btn-warning btn-sm doProModify" value="修改"  name="toModify" data-value="${p.productId }">
                            <!-- <input type="button" class="btn btn-danger btn-sm doProDisable" value="禁用"> -->
                            <!-- 注释掉上一行的input标签  添加   href="${pageContext.request.contextPath }/product/removeById?id=${p.productId }&pageNo=${pageProductList.pageNum }" -->
                            <a class="btn btn-danger btn-sm doProDisable" href="${pageContext.request.contextPath }/product/removeById?id=${p.productId }&pageIndex=${pageSupport.currentPageNo}">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
                <c:import url="../rollpage.jsp">
                    <c:param name="totalCount" value="${pageSupport.totalCount}"/>
                    <c:param name="currentPageNo" value="${pageSupport.currentPageNo}"/>
                    <c:param name="totalPageCount" value="${pageSupport.totalPageCount}"/>
                </c:import>
            </form>
        </div>
        <div class="modal fade" tabindex="-1" id="myProduct">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">商品修改</h4>
                    </div>
                    <form action="${pageContext.request.contextPath }/product/modifyProduct" method="post" enctype="multipart/form-data">
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label for="modifyId" class="col-sm-4 control-label">编号：</label>
                            <div class="col-sm-4">
                                <!-- 添加隐藏域 -->
                                <input type="hidden" name="pageIndex" id="pageIndex"  value="${pageSupport.currentPageNo }" />
                                <input type="text" class="form-control" id="modifyId" name="modifyId" readOnly="readonly">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="modifyName" class="col-sm-4 control-label">商品名称</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyName"  name="modifyName">
                            </div>
                        </div>
                        <br>

                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">商品图片:</label>
                            <div class="col-sm-4">
                                <a href="javascript:;" class="file">选择文件
                                    <input type="file" name="file">
                                </a>
                            </div>
                        </div>
                        <br>

                        <div class="row text-right">
                            <label for="modifyPrice" class="col-sm-4 control-label">商品价格：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyPrice" name="modifyPrice">
                            </div>
                        </div>
                        <br>
                        <!-- 添加  商品类型的div  start -->
                        <div class="row text-right">
                            <label for="modifyTypeId" class="col-sm-4 control-label">商品类型:</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="modifyTypeId" id="modifyTypeId">
                                    <option value="-1">--请选择--</option>
                                    <c:forEach items="${typeList}" var="type">
                                        <option value="${type.id }">${type.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <!-- 添加  商品类型的div  end -->
                        <br>
                    </div>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-primary updatePro" value="修改"/>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>
